﻿@{
    ViewBag.Title = " 兑礼网控制中心-会员管理";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<style>
    .fitem label {
        display: inline-block;
        margin-top: 10px;
        width: 110px;
    }

    .fitems {
        margin-left: 20px;
        float: left;
        padding:10px 0px;
    }
</style>
@*<div class="easyui-layout" style="width:100%;height:100%;">*@
<div id="ToolbarPanel" class="searchbox easyui-panel" title="搜索条件" style="width:100%" data-options="iconCls:'icon-search',collapsed:false,collapsible:true,closable:false,">

    <div class="fitems">
        <label>关键字(名称/电话)</label>
        <input id="KeyWord" class="easyui-textbox" data-options="onChange:search">
    </div>
    <div class="fitems">
        <label>是否兑换</label>
        <select id="duihuan" class="easyui-combobox" style="width:150px;" data-options="onSelect:search">
            <option value="-1" selected="selected">---请选择---</option>
            <option value="1">已兑换</option>
            <option value="0">未兑换</option>
            <option value="2">已删除</option>
        </select>
    </div>

</div>
<div id="toolbar">
    <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-add" plain="true" onclick="newhuiyuan()">添加会员</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-edit" plain="true" onclick="edithuiyuan()">编辑会员</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-remove" plain="true" onclick="delhuiyuan()">删除会员</a>
</div>
<table id="dg" style="width: 100%;" class="easyui-datagrid" method="POST" url="@Url.Action("GetList", "Member")" toolbar="#toolbar" pagination="true" rownumbers="true" fitcolumns="true" singleselect="true" autorowheight="true" resizable="true">
    <thead>
        <tr>
            <th field="MemberName">会员名称</th>
            <th field="loginname" width="75">账号</th>
            <th field="password" width="75">密码</th>
            <th field="Phone" width="75">会员电话</th>
            <th field="Codes" width="50">会员验证码</th>
            <th field="Memberlevel" width="50">会员等级</th>
            <th field="IsActiveText" width="50">是否兑换</th>
        </tr>
    </thead>
</table>

@*</div>*@
<div id="dlg" modal="true" class="easyui-dialog" style="width:480px;height:400px;padding:10px 20px" closed="true" buttons="#dlg-buttons">
    <form id="fm" method="post">
        <input name="ID" hidden="hidden" value="0" />
        <input name="Codes" hidden="hidden" />
        <input name="IsActive" hidden="hidden"/>
        <input name="IsValid" hidden="hidden" />
        <div class="fitem" style="width:100%;">
            <label>会员名称</label>
            <input name="MemberName" class="easyui-textbox">
        </div>
        <div class="fitem" style="width:100%;">
            <label>会员电话</label>
            <input name="Phone" class="easyui-textbox">
        </div>
        <div class="fitem" style="width: 100%;">
            <label>会员等级</label>
            <input id="Levels" class="easyui-combobox" name="Levels" require="true"
                   data-options="valueField:'ID',textField:'Memberlevel',url:'@Url.Action("GetAllLevel", "Member")' ">
            @*<input id="Pirce" name="Pirce" class="easyui-numberbox" required="true" data-options="min:0,precision:2" />*@
        </div>
        <div class="fitem" style="width:100%;">
            <label>登录账号</label>
            <input name="loginname" class="easyui-textbox">
        </div>
        <div class="fitem" style="width:100%;">
            <label>登录密码</label>
            <input name="password" class="easyui-textbox">
        </div>
    </form>
</div>
<div id="dlg-buttons">
    <a href="javascript:void(0)" class="easyui-linkbutton c6" iconcls="icon-ok" onclick="save()" style="width:90px">保存</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')" style="width:90px">取消</a>
</div>

<script type="text/javascript">
    $(function () {
        $('#ToolbarPanel').panel({
            onExpand: function () {
                $('#dg').datagrid('resize');
            },
            onCollapse: function () {
                $('#dg').datagrid('resize');
            }
        });
    });


    function newhuiyuan() {
        //新增
        $('#dlg').dialog({
            title: '新增会员',
            width: 500,
            height: 280,
            closed: false,
            cache: false,
            modal: true
        }).dialog('center');
        $('#fm').form('clear');//清空表单
    }

    function save() {
        $('#fm').form('submit', {
            url: '/MemBer/Save',
            onSubmit: function () {
                return $(this).form('validate');
            },
            success: function (result) {
                var result = eval('(' + result + ')');
                if (result.success == true) {
                    $('#dlg').dialog('close');        // 关闭弹出框
                    $('#dg').datagrid('reload');    // 重新加载表数据

                } else {
                    $.messager.alert('错误',result.msg);
                }
            }
        });
    }

    function edithuiyuan() {
        var row = $('#dg').datagrid('getSelected');
        if (row) {
            $("#fileList").html("");
            $('#fm').form('clear');
            $('#dlg').dialog({
                title: '修改会员',
                width: 500,
                height: 280,
                closed: false,
                cache: false,
                modal: true
            }).dialog('center');
            $('#fm').form('load', row);//表单赋值
        }
        else {
            $.messager.alert("警告", "请选择一条！");
        }

    }


    function delhuiyuan() {
        var row = $('#dg').datagrid('getSelected');
        if (row) {
            $.messager.confirm('警告', '你确定要删除当前选中数据?', function (r) {
                if (r) {
                    $.post("@Url.Action("Del", "MemBer")", { id: row.ID }, function (data) {
                        if (data.success == true) {
                            $('#dg').datagrid('reload');    // 重新加载表数据
                        }
                        else {
                            $.messager.alert('错误', '操作失败！');
                        }
                    });
                }
            });
        }
        else {
            $.messager.alert("警告", "请选择一条！");
        }
    }


    function formatterurl(val, row) {
        return val != null && val != "" ? '<img src=' + val + ' style="max-width:40px;max-height:20px;">' : "";
    }

    function search() {
        var KeyWord = $("#KeyWord").textbox('getValue');
        var isactive = $("#duihuan").combobox('getValue');
        $('#dg').datagrid('reload', { KeyWord: KeyWord, duihuan: isactive });
    }
</script>
